package com.happycat.service.impl;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.happycat.mobile.model.UserAddressBook;
import com.happycat.mobile.service.GenerateIdService;
import com.happycat.mobile.service.UserAddressBookService;
import com.happycat.mapper.UserAddressBookMapper;
import com.happycat.SysContants;
import com.happycat.ResponseModel;
import com.happycat.ResponseHeaderModel;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.happycat.Pagination;
/**
 * Module: UserAddressBook.java
 * 
 * @author liaoyong
 * @since JDK 1.8
 * @version 1.0
 * @date 2020-08-01
 * @Descriptions:
 */
@Service
public class UserAddressBookServiceImpl extends ServiceImpl<UserAddressBookMapper, UserAddressBook> implements UserAddressBookService {
 	
	@Autowired
	private GenerateIdService generateIdService;
	
 	public ResponseModel<UserAddressBook> selectOne(UserAddressBook userAddressBook){
 		Wrapper<UserAddressBook> queryWrapper = new QueryWrapper<>(userAddressBook);
		ResponseModel<UserAddressBook> responseModel = new ResponseModel<>();
		responseModel.setCode(SysContants.SYS_SUCCESS_CODE);
		responseModel.setMessage("查询成功");
		responseModel.setData(getOne(queryWrapper));
		return responseModel;
 	
 	}
	
	public ResponseHeaderModel	add(UserAddressBook userAddressBook){
		ResponseHeaderModel responseHeaderModel = new ResponseHeaderModel();
		userAddressBook.setId(generateIdService.nextDefaultSerialNumber());
		boolean result = save(userAddressBook);
		if(result) {
			responseHeaderModel.setCode(SysContants.SYS_SUCCESS_CODE);
			responseHeaderModel.setMessage("新增成功");
		}else {
			responseHeaderModel.setCode(SysContants.SYS_FAIL_CODE);
			responseHeaderModel.setMessage("新增失败");
		}
		return responseHeaderModel;
	}
	
	public ResponseHeaderModel	modify(UserAddressBook userAddressBook){
			ResponseHeaderModel responseHeaderModel = new ResponseHeaderModel();
		
		boolean result = updateById(userAddressBook);
		if(result) {
			responseHeaderModel.setCode(SysContants.SYS_SUCCESS_CODE);
			responseHeaderModel.setMessage("修改成功");
		}else {
			responseHeaderModel.setCode(SysContants.SYS_FAIL_CODE);
			responseHeaderModel.setMessage("修改失败");
		}
		return responseHeaderModel;
	}
	
	public ResponseModel<Page<UserAddressBook>> pageList(Pagination<UserAddressBook>page){
		ResponseModel<Page<UserAddressBook>> responseModel = new ResponseModel<>();
		responseModel.setCode(SysContants.SYS_SUCCESS_CODE);
		responseModel.setMessage("查询成功");
		responseModel.setData(this.baseMapper.pageList(page));
		return responseModel;
	}
}
